package com.ljc.service.impl;

import com.github.pagehelper.PageHelper;
import com.ljc.dao.IUserDao;
import com.ljc.model.User;
import com.ljc.model.User;
import com.ljc.service.IUserService;
import com.ljc.utils.BeanMapUtils;
import com.ljc.utils.MapParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("userService")
public class UserServiceImpl implements IUserService {

    @Autowired
    private IUserDao userDao;


    @Override
    public User userLogin(User user) {
        User u = userDao.userLogin(user);
        return u;
    }
    public User login(String username, String password){
        Map<String, Object> map = MapParameter.getInstance().add("username",username).add("password",password).getMap();
        return userDao.detail(map);
    }

    @Override
    public void register(User user) {
        userDao.register(user);
    }

    @Override
    public int selectId(User user) {
        return userDao.selectId(user);
    }

    public int create(User user){

        return userDao.create(user);

    }
    public int delete(String username){
        return userDao.delete(MapParameter.getInstance().addname(username).getMap());
    }
    public int update(User user){
        Map<String, Object> map = MapParameter.getInstance().put(BeanMapUtils.beanToMapForUpdate(user)).addId(user.getId()).getMap();
        return userDao.update(map);
    }
    public List<User> query(User user){
        PageHelper.startPage(user.getPage(),user.getLimit());
        Map<String, Object> map = MapParameter.getInstance().put(BeanMapUtils.beanToMap(user)).getMap();
        return userDao.query(map);
    }

    public User detail(Integer id){
        return userDao.detail(MapParameter.getInstance().addId(id).getMap());
    }

    public int count(User user){
        Map<String, Object> map = MapParameter.getInstance().put(BeanMapUtils.beanToMap(user)).getMap();
        return userDao.count(map);
    }
}